#define DRIVER

#include "wdm.h"
#include "stdarg.h"
#include "stdio.h"

#include "usbdi.h"
#include "usbdlib.h"
#include "D12.h"

#include "d12irp.h"

NTSTATUS
D12_ResetIrpQueue(
    IN  PDEVICE_OBJECT DeviceObject
    )
{
    PDEVICE_EXTENSION deviceExtension;
    ULONG i;

    D12_KdPrint (("D12TEST.SYS: enter D12_ResetIrpQueue\n"));

    deviceExtension = DeviceObject->DeviceExtension;
	for( i=0; i<D12_MAX_PENDING_IRPS; i++)
		deviceExtension->pendingIRP[i]=0;

	return STATUS_SUCCESS;
}

NTSTATUS
D12_CancelAllPendingIrps(
    IN  PDEVICE_OBJECT DeviceObject
	)
{
    PDEVICE_EXTENSION deviceExtension;
    NTSTATUS ntStatus;
    ULONG i;

    D12_KdPrint (("D12TEST.SYS: enter D12_CancelPendingIrps\n"));

    deviceExtension = DeviceObject->DeviceExtension;
	for( i=0; i<D12_MAX_PENDING_IRPS; i++) {
		if(deviceExtension->pendingIRP[i]) {
				ntStatus = IoCancelIrp(deviceExtension->pendingIRP[i]);
				deviceExtension->pendingIRP[i] = 0;
		}
	}

    D12_KdPrint (("D12TEST.SYS: exit D12_CancelPendingIrps\n"));
	return ntStatus;
}

NTSTATUS
D12_RemovePendingIrp(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
	)
{
    PDEVICE_EXTENSION deviceExtension;
    ULONG i;

    D12_KdPrint (("D12TEST.SYS: enter D12_RemovePendingIrp\n"));

    deviceExtension = DeviceObject->DeviceExtension;
	for( i=0; i<D12_MAX_PENDING_IRPS; i++)
		if(deviceExtension->pendingIRP[i] == Irp)
				deviceExtension->pendingIRP[i] = 0;

    D12_KdPrint (("D12TEST.SYS: exit D12_RemovePendingIrp\n"));
	return STATUS_SUCCESS;
}

NTSTATUS
D12_AddPendingIrp(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
	)
{
    PDEVICE_EXTENSION deviceExtension;
    ULONG i;

    D12_KdPrint (("D12TEST.SYS: enter D12_AddPendingIrp\n"));

    deviceExtension = DeviceObject->DeviceExtension;
	for( i=0; i<D12_MAX_PENDING_IRPS; i++) {
		if(deviceExtension->pendingIRP[i] == 0) {
				deviceExtension->pendingIRP[i] = Irp;
				break;
		}
	}

    D12_KdPrint (("D12TEST.SYS: exit D12_AddPendingIrp\n"));
	return STATUS_SUCCESS;
}